﻿using AutoMapper;
using B.S.BasicData.Domain;
using B.S.BasicData.ErrorCode;
using B.S.BasicData.Infrastructure.Interfance;
using B.S.BasicData.Read.Apilication.Common.RolePremiss;
using B.S.BasicData.Read.DTOS;
using MediatR;

namespace B.S.BasicData.Read.Apilication.Handler.RolePremiss
{
    public class SetmenuHandler : IRequestHandler<SetmenuCommon, ApiResult<List<int>>>
    {
        private readonly IBaseRepository<RolePermissModel> rolepermissRepo;
        private readonly IMapper mapper;
        private readonly IBaseRepository<menuModel> menuRepo;
        private readonly IBaseRepository<RoleModel> roleRepo;

        public SetmenuHandler(IBaseRepository<RolePermissModel> rolepermissRepo,IMapper mapper,IBaseRepository<menuModel> menuRepo )
        {
            this.rolepermissRepo = rolepermissRepo;
            this.mapper = mapper;
            this.menuRepo = menuRepo;
        }
        public Task<ApiResult<List<int>>> Handle(SetmenuCommon request, CancellationToken cancellationToken)
        {
            ApiResult<List<int>> res=new ApiResult<List<int>>();

            var info = rolepermissRepo.GetAll().Where(x => x.RoleId == request.RoleId).Select(x=>x.MenuId);
            //var menulist = menuRepo.GetAll().Where(x=>info.Contains(x.MenuId));
            //var model=mapper.Map<List<SetMenuDTO>>(menulist);

            res.Data = info.ToList();
            res.Message = "显示成功";
            res.Code=ApiEnum.Success;
            return Task.FromResult(res);



        }
    }
}
